   package com.javalong.affairs.module.notifything.activity;

import java.util.HashMap;
import java.util.Map;

import com.javalong.affairs.R;
import com.javalong.affairs.base.activity.UIHandlerActivity;
import com.javalong.affairs.base.constant.BundleKey;
import com.javalong.affairs.base.constant.DataType;
import com.javalong.affairs.base.constant.RequestKey;
import com.javalong.affairs.base.listener.BaseResponseListener;
import com.javalong.affairs.base.model.MessageInfo;
import com.javalong.affairs.base.ui.TopTitle;
import com.javalong.affairs.base.utils.HttpUtils;
import com.javalong.affairs.base.utils.TimeUtils;
import com.javalong.affairs.base.utils.UrlUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;

import android.os.Bundle;
import android.widget.TextView;

@ContentView(R.layout.activity_watchmsg)
public class WatchMsgActivity extends UIHandlerActivity {
	@ViewInject(R.id.tv_time)
	private TextView tv_time;
	@ViewInject(R.id.tv_address)
	private TextView tv_address;
	@ViewInject(R.id.tv_sender)
	private TextView tv_sender;
	@ViewInject(R.id.tv_receiver)
	private TextView tv_receiver;
	@ViewInject(R.id.tv_status)
	private TextView tv_status;
	@ViewInject(R.id.tv_content)
	private TextView tv_content;
	@ViewInject(R.id.tv_timelimit)
	private TextView tv_timelimit;
	@ViewInject(R.id.tv_title_content)
	private TextView tv_title;
	@ViewInject(R.id.ui_toptitle)
	private TopTitle topTitle;
	private String msgId;
	private String status;
	private boolean isReceiver;
	private String simpleMsgId;
	private int currType;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ViewUtils.inject(this);
		Bundle bundle = getIntent().getBundleExtra(BundleKey.BUNDLE);
		msgId = bundle.getString(BundleKey.MSGID);
		simpleMsgId = bundle.getString(BundleKey.SIMPLEMSGID);
		status = bundle.getString(BundleKey.SIMPLEMSGSTATUS);
		isReceiver = bundle.getBoolean(BundleKey.ISRECEIVER);
		currType = bundle.getInt(BundleKey.SEARCHTYPE, 0);
		initData();
	}

	private void initData() {
		String url = "";
		if (currType == 2) {
			url = UrlUtils.getUrl("Journal", "outOne_journal");
		} else {
			url = UrlUtils.getUrl("SendMessage", "outOne_messageinfo");
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put(RequestKey.ID, simpleMsgId);
		HttpUtils.post(url, params, new BaseResponseListener(DataType.MESSAGE) {
			@Override
			public void onSuccess(Object obj) {
				super.onSuccess(obj);
				initUI((MessageInfo) obj);
			}
		});
	}

	private void initUI(MessageInfo msgInfo) {
		if (msgInfo != null) {
			tv_time.setText(TimeUtils.getFormatTime2(msgInfo.time));
			tv_address.setText(msgInfo.place);
			tv_sender.setText(msgInfo.nameSend);
			tv_receiver.setText(msgInfo.recipient);
			tv_content.setText(msgInfo.messageData);
			tv_timelimit.setText(msgInfo.timeLimit);
			tv_title.setText(msgInfo.title);
		}
		topTitle.setOnLeftDrawableClick(this);
	}
}
